<?php

namespace App\Repository\Models;

use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class ShopBanners.
 *
 * @package namespace App\Repository\Models;
 */
class ShopBanners extends Model implements Transformable
{
    use TransformableTrait;
    use SoftDeletes;
    protected $table = 'shop_banners';
    
    protected $appends = ['screen_type_name'];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['shop_id','banner_name','banner_url','banner_image','screen_type','created_at','updated_at','deleted_at'];

    // banner 映射
    public static $screen_type_map = [
        1 => '第一屏',
        2 => '第二屏',
        3 => '第三屏',
    ];
    public function getScreenTypeNameAttribute()
    {
        if (isset($this->attributes['screen_type'])) {
            return array_get(self::$screen_type_map, $this->attributes['screen_type']) ?: '-';
        }
    }
    public function setScreenTypeAttribute($val)
    {
        if (key_exists($val,self::$screen_type_map)) {
            $this->attributes['screen_type'] = $val;
        }
    }
}
